import Taro, {Component} from '@tarojs/taro'
import {View} from '@tarojs/components'
import { AtGrid ,AtFloatLayout ,AtNoticebar} from "taro-ui"
import BasePage from "../basePage";

import car from '../../image/ic_find_car.png'
import job from '../../image/ic_job.png'
import houseRent from '../../image/ic_house_rent.png'
import shopRent from '../../image/ic_shop_rent.png'
import forSale from '../../image/ic_for_sale.png'
import infoIcon from '../../image/ic_info.png'
import lifeService from '../../image/ic_life_service.png'
import secondHand from '../../image/ic_second_hand.png'
import otherService from '../../image/ic_other_service.png'

import './allPost.scss'

export default class allPost extends BasePage {

  config = {
    navigationBarTitleText: '信息发布'
  }

  onPullDownRefresh(){
    Taro.stopPullDownRefresh();
  }

  constructor() {
    super(...arguments)
    this.state = {
      postTypeList : [
        {image: job, value: '本地招聘'},
        {image: car, value: '拼车信息'},
        {image: houseRent, value: '房屋租赁', code:13001},
        {image: shopRent, value: '旺铺租售' , code:13002},
        {image: forSale, value: '优惠促销' , code:13004},
        {image: infoIcon, value: '咨询打听', code:13005},
        {image: lifeService, value: '生活服务', code:13006},
        {image: secondHand, value: '二手市场' , code:13007},
        {image: otherService, value: '其他' , code:13008},
      ] ,
      postTypeViewShow:false ,
    }
  }

  componentDidMount(){
  }

  handlePostClick(){
    this.setState({
      postTypeViewShow:true
    })
  }

  handleFloatClose(){
    this.setState({
      postTypeViewShow : false
    })
  }

  handleRidingPost(){
    Taro.navigateTo({
      url: '/pages/post/ridingPost'
    })
  }

  handleDriverPost(){
    Taro.navigateTo({
      url: '/pages/post/driverPost'
    })
  }

  onPostTypeClick = (item , index ) =>{
    let url;
    if (index == 0){ // 本地招聘
      url = `/pages/post/jobPost`;
    } else if (index == 1){//  拼车信息
      this.handlePostClick()
    } else {
      console.log('code=-================' + item.code)
      url = `/pages/post/shopInfoPost?categoryId=` + item.code;
    }
    if (url){
      Taro.navigateTo({
        url : url
      })
    }
  }

  render(){

    return(
      <View className='all-post-container'>
        <AtNoticebar>
          免责声明：本平台不对任何人提供任何形式的担保，所有法律信息仅供参考，不承担由此产生的任何民事及法 律责任。用户使用本平台即视为同意。
        </AtNoticebar>
        <AtGrid data={this.state.postTypeList} hasBorder onClick={this.onPostTypeClick.bind(this)} columnNum={3} />
        <AtFloatLayout isOpened={this.state.postTypeViewShow} title='选择您要发布的信息类型' onClose={this.handleFloatClose.bind(this)}>
          <View className='post-item' onClick={this.handleRidingPost.bind(this)}>人找车</View>
          <View className='post-item' onClick={this.handleDriverPost.bind(this)} >车找人</View>
        </AtFloatLayout>
      </View>
    )

  }

}
